package com.atguigu.lease.common.exception;

import com.atguigu.lease.common.result.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * projectName: com.atguigu.lease.common.exception
 *
 * @author: wangs
 * description:
 */

// 全局异常处理器
@RestControllerAdvice
public class GlobelExceptionHandler {

    // 处理异常的方法
    @ExceptionHandler(value = Exception.class)
    public Result doResolveException(Exception e) {
        e.printStackTrace();
        return Result.fail();
    }

    // 处理自定义异常的方法
     @ExceptionHandler(value = LeaseException.class)
    public  Result doResolveException(LeaseException e) {
        e.printStackTrace();
        return Result.fail(e.getCode(),e.getMessage());
     }
}
